<template>
  <div class="flex1" style="background: #f3f6f9">
    <ksd-banner-vip></ksd-banner-vip>
    <div class="gui-paddingn flex justify-between">
      <div class="index-classify-nav">
        <a href="javascript:;" @click="handleChangeTab(-1)" :class="[currentIndex==-1?'checked':'']">全部</a>
        <a href="javascript:;" @click="handleChangeTab(0)" :class="[currentIndex==0?'checked':'']">1~3年</a>
        <a href="javascript:;" @click="handleChangeTab(1)" :class="[currentIndex==1?'checked':'']">3~5年</a>
        <a href="javascript:;" @click="handleChangeTab(2)" :class="[currentIndex==2?'checked':'']">5~8年</a>
        <a href="javascript:;" @click="handleChangeTab(3)" :class="[currentIndex==3?'checked':'']">10年以上</a>
      </div>
      <div>
        <span class="fw red mr10 fz12">下载遇到问题：请联系微信 xuchengfeifei</span>
      </div>
    </div>
    <div class="index-resume-panel gui-paddingt mt5">
      <div class="template-common-cards hover" v-for="(item,index) in tableData" data-template="resumeItem"
           data-id="206" data-tag-id="">
        <div class="template-common-image">
          <img :src="item.cover" alt="">
          <div class="template-view-layer" v-if="item.isBuy || userStore.viptype > 1" @click="handleDownload(item)">
            <span class="make-btn"><span>已购买，直接下载</span></span>
          </div>
          <div class="template-view-layer" v-else @click="handleOpenPayDiaolog(item)">
            <span class="make-btn"><span>购买此简历</span></span>
          </div>
        </div>
        <div class="template-common-info">
          <span class="template-name" data-id="206">{{item.title}}</span>
          <div class="template-use">
            <span class="tota mr5">下载次数：{{item.downloadNum || 0}}</span>
            <button class="ml10 mr10" @click="handleOpenPdf(item)">预览</button>
            <span class="red pointer fw" title="点击下载" v-if="item.isBuy || userStore.viptype > 1"  @click="handleDownload(item)">已订阅</span>
          </div>
        </div>
      </div>
    </div>
    <teleport to="body">
      <k-login ref="loginRef" @success="handleLoginFinshed"></k-login>
      <ksd-resume-pay-template ref="resumePayRef"></ksd-resume-pay-template>
      <ksd-resume-pdf ref="resumePdfRef"></ksd-resume-pdf>
    </teleport>
  </div>
</template>
<script setup>
const tableData = ref([])
const loginRef = ref({})
const resumePdfRef = ref({})
const resumePayRef = ref({})
const currentIndex = ref(-1)
const userStore = useStore.userState()
const queryParams = ref({
  pageNo:1,
  pageSize:10,
  keyword:"",
  rtype:0
})

const handleChangeTab = (index)=>{
  queryParams.value.rtype = index+1
  currentIndex.value = index
  handleLoadData()
}


const handleOpenPdf = async (item) => {
  resumePdfRef.value.handleOpen(item.id)
}

const handleOpenPayDiaolog = async (item) => {
  await useLoginDialog()
  resumePayRef.value.handleOpen(item.id, item.price,item.title)
}

const handleLoginFinshed = async () => {
  window.location.reload()
}

const handleLoadData = async () => {
  const resp = await useLoadResumeTemplatesApi(queryParams.value)
  tableData.value = resp.data
}

const handleDownload = async (item) => {
  try {
    const resp = await useLoadResumeTemplateFileDetail(item.id)
    var objectUrl = resp.data
    let a = document.createElement('a')
    a.style.display = 'none'
    a.href = objectUrl
    a.download = item.title
    document.body.appendChild(a)
    a.click()
    document.body.removeChild(a)
    useMessage().success("下载成功！");
  } catch (e) {
    if (e.code == 701) {
      useLoginDialog()
    }
    useMessage().error(e.msg)
    if (e.code == 702) {
      handleOpenPayDiaolog(item)
    }
  }
}


definePageMeta({
  layout: "nindex"
})

onMounted(async () => {
  handleLoadData()
})

</script>

<style scoped lang="scss">
.index-resume-panel {
  display: grid;
  font-size: 12px;
  grid-gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(15%, 1fr));
}

.template-common-cards {
  display: inline-block;
  position: relative;
  height: auto;
  border-radius: 4px;
  background:#fff;
  padding:10px;
  user-select: none;
  transform: translate3d(0, 0, 0) scale3d(1, 1, 1);
  transition: transform 0.15s;
}

.template-common-cards .template-common-image {
  position: relative;
  width: 100%;
  height: auto;
  background-color: #ffffff;
  border-radius: 4px;
  overflow: hidden;
}

.template-common-cards .template-common-image::before {
  content: "";
  display: block;
  padding-top: 141.46%;
}

.template-common-cards .template-common-image img {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.template-common-cards .template-common-image img.school-logo, .template-common-cards .template-common-image img.school-background {
  display: none;
  position: absolute;
  top: auto;
  left: auto;
  width: auto;
  height: auto;
  object-fit: fill;
}

.template-common-cards .template-common-image img.school-logo[src^="http"], .template-common-cards .template-common-image img.school-background[src^="http"] {
  display: block;
}

.template-common-cards .template-common-image .template-view-layer {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  opacity: 0;
  background-color: rgba(0, 0, 0, 0.5);
  transition: all 0.3s;
}

.template-common-cards .template-common-image .template-view-layer .make-btn {
  display: table;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50%;
  height: 8%;
  background-color: #00c091;
  border-radius: 6px;
  text-align: center;
  font-size: 13px;
  color: #ffffff;
  cursor: pointer;
  transform: translate(-50%, -50%);
  transition: all 0.3s;
}

.template-common-cards .template-common-image .template-view-layer .make-btn > span {
  display: table-cell;
  vertical-align: middle;
}

.template-common-cards .template-common-image .template-view-layer .make-btn:hover {
  background-color: #00b185;
  box-shadow: 0px 4px 8px 0px rgba(0, 37, 58, 0.08);
}

.template-common-cards .template-common-image .template-view-layer .enlarge-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 28px;
  height: 28px;
  padding: 7px;
  background-color: rgba(0, 0, 0, 0.6);
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.3s;
}

.template-common-cards .template-common-image .template-view-layer .enlarge-btn:hover {
  background-color: #000000;
}

.template-common-cards .template-common-image .template-view-layer .enlarge-btn .icon {
  display: block;
  width: 14px;
  height: 14px;
}

.template-common-cards .template-common-info {
  position: relative;
  width: 100%;
  height: 48px;
  line-height: 48px;
  padding: 0 3%;
  border-radius: 0 0 4px 4px;
  text-align: left;
}

.template-common-cards .template-common-info .template-name {
  position: absolute;
  top: 0;
  left: auto;
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: #46505a;
}

.template-common-cards .template-common-info .template-like, .template-common-cards .template-common-info .template-use {
  float: right;
}

.template-common-cards .template-common-info .template-like {
  margin-right: 8px;
}

.template-common-cards .template-common-info .template-like .icon, .template-common-cards .template-common-info .template-use .icon {
  display: inline-block;
  vertical-align: middle;
  width: 12px;
  height: 12px;
  margin-right: 4px;
}

.template-common-cards .template-common-info .template-like .icon {
  background-position: 0 0;
}

.template-common-cards .template-common-info .template-use .icon {
  background-position: -32px -26px;
}

.template-common-cards .template-common-info .template-like.active .icon {
  background-position: -25px 0;
}

.template-common-cards .template-common-info .template-like .total, .template-common-cards .template-common-info .template-use .total {
  display: inline-block;
  vertical-align: middle;
  line-height: 18px;
  font-size: 12px;
  color: #bdc7d0;
}

.template-common-cards .template-common-info .template-like.active .total {
  color: #00c091;
}

.template-common-cards .template-common-info .template-like-btn {
  display: none;
  position: absolute;
  top: 50%;
  right: 3%;
  z-index: 1;
  margin-top: -12px;
  width: 90px;
  height: 24px;
  line-height: 22px;
  text-align: center;
  border-radius: 4px;
  border: solid 1px #bdc7d0;
  cursor: pointer;
}

.template-common-cards .template-common-info .template-like-btn.disabled {
  pointer-events: none;
}

.template-common-cards .template-common-info .template-like-btn .normal {
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0.65;
}

.template-common-cards .template-common-info .template-like-btn .normal:hover {
  opacity: 1;
  transition: all 0.3s;
}

.template-common-cards .template-common-info .template-like-btn .active {
  display: none;
  width: 100%;
  height: 100%;
}

.template-common-cards .template-common-info .template-like-btn .icon {
  display: inline-block;
  vertical-align: middle;
  width: 12px;
  height: 12px;
  margin-right: 8px;
}

.template-common-cards .template-common-info .template-like-btn .normal .icon {
  background-position: -50px 0;
}

.template-common-cards .template-common-info .template-like-btn .active .icon {
  background-position: -75px 0;
}

.template-common-cards .template-common-info .template-like-btn .name {
  display: inline-block;
  vertical-align: middle;
  font-size: 14px;
  color: #46505a;
}

.template-common-cards .template-common-info .template-like-btn.active {
  border-color: #00c091;
  background-color: #00c091;
}

.template-common-cards .template-common-info .template-like-btn.active .active {
  display: block;
}

.template-common-cards .template-common-info .template-like-btn.active .normal {
  display: none;
}

.template-common-cards .template-common-info .template-like-btn.active .name {
  color: #ffffff;
}

/* 手机样式 */
.template-common-cards.wap {
  box-shadow: none;
  border-radius: 10% / 5%;
}

.template-common-cards.wap .template-common-image::before {
  padding-top: 202.12%;
}

.template-common-cards.wap .template-common-image img {
  position: absolute;
  top: 1.75%;
  left: 3.5%;
  width: 93%;
  height: 96%;
  object-fit: cover;
  border-radius: 8% / 4%;
}

.template-common-cards.wap .template-common-image .template-view-layer {
  left: 1%;
  width: 99%;
  border-radius: 10% / 5%;
}

.template-common-cards.wap .template-common-image .template-view-layer .enlarge-btn {
  top: 20px;
  right: 20px;
}

.template-common-cards.wap .template-common-image .template-view-layer .make-btn {
  height: 5.8%;
}

.template-common-cards.wap .template-common-info {
  position: absolute;
  z-index: 3;
  bottom: -32px;
  height: 32px;
  line-height: 32px;
  background-color: transparent;
  transition: all 0.15s;
}

.template-common-cards.wap .template-common-info .template-like-btn {
  right: 8%;
  transition: all 0.3s;
}

/* 骨架样式 */
.template-common-cards.skeleton {
  background-color: #ffffff;
  border: none !important;
  box-shadow: none !important;
}

.template-common-cards.skeleton .template-common-image, .template-common-cards.skeleton .template-common-info {
  opacity: 0;
}

.template-common-cards.hover:hover {
  box-shadow: 0px 16px 22px 2px rgba(0, 37, 58, 0.24);
  transform: translateY(1%) scale(1.01);
}

.template-common-cards.hover:hover .template-common-image {
  border-radius: 4px 4px 0 0;
}

.template-common-cards.hover:hover .template-common-image .template-view-layer {
  opacity: 1;
}

.template-common-cards.hover:hover .template-common-info .template-like{
  display: none;
}

.template-common-cards.hover:hover .template-common-info .template-like-btn {
  display: block;
}

.template-common-cards.wap.hover:hover {
  transform: translateY(2.5%) scale(1.1);
  box-shadow: none;
}

.template-common-cards.wap.hover:hover .template-common-image {
  filter: drop-shadow(0px 16px 22px rgba(0, 37, 58, 0.24));
}

.template-common-cards.wap.hover:hover .template-common-info {
  position: absolute;
  bottom: 4%;
  padding: 0 8%;
}

.template-common-cards.wap.hover:hover .template-common-info .template-name {
  color: #ffffff;
}

.template-common-cards.wap.hover:hover .template-common-info .template-like-btn:hover {
  background-color: #00c091;
  border-color: #00c091;
}

.template-common-cards.wap.hover:hover .template-common-info .template-like-btn .normal {
  opacity: 1;
}

.template-common-cards.wap.hover:hover .template-common-info .template-like-btn .icon {
  background-position: -75px 0;
}

.template-common-cards.wap.hover:hover .template-common-info .template-like-btn .name {
  color: #ffffff;
}

.index-classify-nav a {
  padding-top: 20px;
  margin-right: 20px;
  line-height: 16px;
}

.index-classify-nav > a:hover ,.index-classify-nav > a.checked{
  color: #00c091;
  font-weight: bold;
}
</style>
